package cn.yunhe.service.impl;

import cn.yunhe.entity.AirModel;
import cn.yunhe.mapper.IAireDao;
import cn.yunhe.service.IAirService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("airService")
public class AirServiceImpl implements IAirService {

    @Resource(name = "IAirDao")
    private IAireDao aireDao;

    @Override
    @Transactional
    public List<AirModel> findAll() throws Exception {
        return aireDao.findAll();
    }

    @Override
    public int addAir(AirModel model) throws Exception {
        try {
            return aireDao.addAir(model);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int updateAir(AirModel model) throws Exception {
        return aireDao.updateAir(model);
    }

    @Override
    public List<AirModel> findAirByCondition(String district) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("district", district);
        return aireDao.findAirByCondition(map);
    }

    @Override
    public AirModel selectOneById(Integer id) throws Exception {
        return aireDao.selectOneById(id);
    }

    public IAireDao getAireDao() {
        return aireDao;
    }

    public void setAireDao(IAireDao aireDao) {
        this.aireDao = aireDao;
    }
}
